package org.activequant.core.domainmodel.marketdepth;

import static org.activequant.util.tools.IdentityUtils.equalsTo;
import static org.activequant.util.tools.IdentityUtils.safeCompare;
import static org.activequant.util.tools.IdentityUtils.safeHashCode;

import java.io.Serializable;
/**
 * MarketDepthRow implements Comparable&lt;MarketDepthRow&gt;, Serializable.<br/>
 * Holds the following associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>marketMaker(String)</li>
 * <li>price(Double)</li>
 * <li>size(Integer)</li>
 * <li>cumSize(Integer)</li>
 * <li>avgPrice(Double)</li>
 * </ul>
 * @author Dimitar
 *
 */
public class MarketDepthRow implements Comparable<MarketDepthRow>, Serializable{
	private static final long serialVersionUID = -3216248673154725530L;
	/**
	 * private Long id = null;
	 */
	private Long id = null;
	/**
	 * private String marketMaker;
	 */
	private String 	marketMaker;
	/**
	 * private Double price;
	 */
	private Double price;
	/**
	 * private Integer size;
	 */
	private Integer size;
	/**
	 * private Integer cumSize;
	 */
	private Integer cumSize;
	/**
	 * private Double avgPrice;
	 */
	private Double avgPrice;
	/**
	 * Constructs a MarketDepthRow using the given marketMaker(String), price(Double) and size(Integer) to set its associated marketMaker(String), price(Double) and size(Integer).
	 * It also sets its associated cumSize(Integer) and avgPrice(Double) to 0s.
	 * @param marketMaker
	 * @param price
	 * @param size
	 */
	public MarketDepthRow(String marketMaker, Double price, Integer size) {
		this.marketMaker = marketMaker;
		this.price = price;
		this.size = size;
		this.cumSize = 0;
		this.avgPrice = 0d;
	}
	/**
	 * Returns the associated id(Long)
	 * @return
	 */
	public Long getId() {
		return id;
	}
	/**
	 * Sets the associated id(Long) with the given id(Long)
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * Returns the associated marketMaker(String)
	 * @return
	 */
	public String getMarketMaker() {
		return marketMaker;
	}
	/**
	 * Sets the associated marketMaker(String) with the given marketMaker(String)
	 * @param marketMaker
	 */
	public void setMarketMaker(String marketMaker) {
		this.marketMaker = marketMaker;
	}
	/**
	 * Returns the associated price(Double)
	 * @return
	 */
	public Double getPrice() {
		return price;
	}
	/**
	 * Sets the associated price(Double) with the given price(Double)
	 * @param price
	 */
	public void setPrice(Double price) {
		this.price = price;
	}
	/**
	 * Returns the associated size(Integer)
	 * @return
	 */
	public Integer getSize() {
		return size;
	}
	/**
	 * Sets the associated size(Integer) with the given size(Integer)
	 * @param size
	 */
	public void setSize(Integer size) {
		this.size = size;
	}
	/**
	 * Returns the associated cumSize(Integer)
	 * @return
	 */
	public Integer getCumSize() {
		return cumSize;
	}
	/**
	 * Sets the associated cumSize(Integer) with the given cumSize(Integer)
	 * @param cumSize
	 */
	public void setCumSize(Integer cumSize) {
		this.cumSize = cumSize;
	}
	/**
	 * Returns the associated avgPrice(Double)
	 * @return
	 */
	public Double getAvgPrice() {
		return avgPrice;
	}
	/**
	 * Sets the associated avgPrice(Double) with the given avgPrice(Double)
	 * @param avgPrice
	 */
	public void setAvgPrice(Double avgPrice) {
		this.avgPrice = avgPrice;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		// ATTENTION: keep in sync with compareTo();
		return 
		safeHashCode(this.getPrice()) + 
		safeHashCode(this.getSize()) + 
		safeHashCode(this.getCumSize())+ 
		safeHashCode(this.getAvgPrice()) + 
		safeHashCode(this.getMarketMaker());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object other) {
		// NOTE: delegates to compareTo()
		return equalsTo(this, other);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public int compareTo(MarketDepthRow other) {
		// ATTENTION: keep in sync with hashCode();
		int rc;
		rc = safeCompare(this.getPrice(), other.getPrice());
		if (rc != 0) return rc;
		rc = safeCompare(this.getSize(), other.getSize());
		if (rc != 0) return rc;
		rc = safeCompare(this.getCumSize(), other.getCumSize());
		if (rc != 0) return rc;
		rc = safeCompare(this.getAvgPrice(), other.getAvgPrice());
		if (rc != 0) return rc;
		rc = safeCompare(this.getMarketMaker(), other.getMarketMaker());
		if (rc != 0) return rc;
		return rc;
	}
	
	@Override
	public String toString() {
		return size+"@"+price+" avg:"+avgPrice+" cum:"+cumSize+" MM:"+marketMaker;
	}
}
